package com.sky.mapper.user;

import com.sky.pojo.AddressBook;
import com.sky.vo.AddressBookVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    /**
     * 新增地址
     * @param addressBook
     */
    void addAddr(AddressBook addressBook);

    /**
     * 查询用户所有地址
     * @param currentId
     * @return
     */
    @Select("select * from address_book where user_id = #{currentId}")
    List<AddressBookVO> queryList(Long currentId);

    /**
     * 查询默认地址
     * @param currentId
     * @return
     */
    @Select("select * from address_book where user_id = #{currentId} and is_default = 1")
    AddressBookVO queryDefAddr(Long currentId);

    /**
     * 修改用户地址
     * @param addressBook
     */
    void update(AddressBook addressBook);

    /**
     * 删除地址
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void delById(Long id);

    /**
     * 根据id查询地址
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBookVO queryById(Long id);

    /**
     * 将当前用户的所有地址设置为非默认
     * @param currentId
     */
    @Update("update address_book set is_default = 0 where user_id = #{currentId}")
    void setAllAddrUndefult(Long currentId);

    /**
     * 设置默认地址
     * @param id
     */
    @Update("update address_book set is_default = 1 where id = #{id}")
    void setDefAddr(Long id);
}
